package orderReturn.create;

import orderReturn.create.domain.*;

import javax.annotation.Resource;

/**
 * Author  : gaojun            <br/>
 * Date    : 2020/9/28                          <br/>
 * Time    : 7:31 下午                         <br/>
 * ---------------------------------------    <br/>
 * Desc    :
 */
public abstract class AbstractReturnCreator implements ReturnCreator {

    @Resource
    private ReturnInitPhase initPhase;
    @Resource
    private ReturnDateCheckPhase checkPhase;
    @Resource
    private ReturnBuildPhase buildPhase;
    @Resource
    private ReturnSavePhase savePhase;
    @Resource
    private ReturnCreatePostProcessPhase postProcessPhase;

    public void create(CreateCmd createCmd) {
        ReturnCreateContext returnCreateContext = initReturnCreateContext(createCmd);
        ReturnCheckResult checkResult = checkData(returnCreateContext);
        if (!checkResult.isSuccess()) {
            return;
        }
        Return returnDomain = buildReturn(returnCreateContext);
        ReturnSaveResult returnSaveResult = save(returnDomain);
        postProcess(returnCreateContext, returnSaveResult);
    }

    protected void postProcess(ReturnCreateContext returnCreateContext, ReturnSaveResult returnSaveResult) {
        postProcessPhase.postProcessPhase(returnCreateContext, returnSaveResult);
    }

    protected Return buildReturn(ReturnCreateContext returnCreateContext) {
        return buildPhase.build(returnCreateContext);
    }

    protected ReturnSaveResult save(Return returnDomain) {
        return savePhase.save(returnDomain);
    }

    protected ReturnCheckResult checkData(ReturnCreateContext returnCreateContext) {
        return checkPhase.checkData(returnCreateContext);
    }

    protected ReturnCreateContext initReturnCreateContext(CreateCmd createCmd) {
        return initPhase.init(createCmd);
    }
}
